﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.NetworkInformation;

namespace Alex.Library.Net.Communications
{
    /// <summary>
    /// 网络通讯相关Helper类
    /// </summary>
    public sealed class NetworkHelper
    {
        /// <summary>
        /// 通过ping命令测试连接
        /// </summary>
        /// <param name="hostNameOrAddress">主机名或IP</param>
        /// <param name="timeout">超时时间(毫秒)，默认2秒</param>
        /// <returns></returns>
        public static bool Ping(string hostNameOrAddress, int timeout = 2000)
        {
            try
            {
                Ping ping = new Ping();
                PingReply reply = ping.Send(hostNameOrAddress, timeout);
                return reply.Status == IPStatus.Success;
            }
            catch
            {
                throw;
            }
        }
    }
}
